var express = require('express');
var router = express.Router();
const { moveFiles, removeFiles } = require("../utils/handleFiles")
/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('index', { title: 'Express' });
})
//车位数据渲染
const { getparkings } = require('../service/parkingsService')

router.get('/getparkings', async function (req, res, next) {
    console.log("111");
    const getpark = await getparkings(req.query);
    
    res.send(getpark);
});

//软删除
const { delparkings } = require('../service/parkingsService')
router.get('/deletepark', async function (req, res, next) {
    const delpark = await delparkings(req.query)
    res.send(delpark)
});

//修改渲染

const { xgindex } = require("../service/parkingsService");
router.get('/xgparking', async function (req, res, next) {
    const data = await xgindex(req.query)
    res.send(data)
});
router.get('/', function (req, res, next) {
    res.render('index', { title: 'Express' });
});

const { addParkings, auditParkings, getState, xginPark } = require('../service/parkingsService')

router.post('/addParkings', async function (req, res, next) {
    const data = await addParkings(req.body)
    if (data.status && req.body.imagesName) {
        moveFiles({
            fromPath: "./public/temp",
            toPath: './public/images',
            filename: req.body.imagesName
        })
        removeFiles("./public/temp")
    }
    res.send(data);
})

//审核车位渲染列表
router.get('/auditParkings', async function (req, res, next) {
    const data = await auditParkings(req.query)
    res.send(data)
})

//
router.get('/getState', async function (req, res, next) {
    console.log(req.query)
    const data = await getState(req.query)
    res.send(data)
})

//修改车位

router.get('/inxgPArkings', async function (req, res, next) {
    const xgpark = await xginPark(req.query)
    res.send(xgpark)
});


module.exports = router
